package cn.ibdsr.human.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;


/**
 * @Description:
 * @Version: 1.0
 * @CreateDate: 2021/3/2 13:38
 * @Author: Swagger2Config
 * Date           Author               Description
 * ------------------------------------------------------
 * 2021/3/2        cdl
 *
 * 接口页面
 * http://localhost:8002/swagger-ui.html
 */
@EnableSwagger2
@Configuration
@ConditionalOnProperty(prefix = "swagger", value = {"enable"}, havingValue = "true")
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.ibdsr.human.controller"))//扫描com路径下的api文档
                .paths(PathSelectors.any())//路径判断
                .build();
    }

    private ApiInfo apiInfo() {
        Contact contact = new Contact("cdl", "", "iamcimon@qq.com");
        return new ApiInfo(
                "SwaggerAPI文档",
                "不断学习，不断进步",
                "1.0",
                "urn:tos",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}